package ua.at.tsvetkov.samizdat.adapters;

import ua.at.tsvetkov.samizdat.R;
import android.app.Activity;
import android.text.Html;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

public class AdtTextListView extends BaseAdapter {

	private Activity	activity;
	private String[]	text;

	public AdtTextListView(Activity activity, String[] text) {
		this.activity = activity;
		this.text = text;
	}

	@Override
	public int getCount() {
		return text.length;
	}

	@Override
	public Object getItem(int position) {
		return text[position];
	}

	@Override
	public long getItemId(int position) {
		return position;
	}

	static class ViewHolder {
		TextView	paragraph;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		View row = convertView;
		ViewHolder item = null;

		if (row == null) {
			LayoutInflater inflater = activity.getLayoutInflater();
			row = inflater.inflate(R.layout.ac_text_flipper_item, parent, false);

			item = new ViewHolder();
			item.paragraph = (TextView) row.findViewById(R.id.ac_text_flipper_item);

			row.setTag(item);
		} else {
			item = (ViewHolder) row.getTag();
		}
		item.paragraph.setText(Html.fromHtml(text[position]));
		return row;
	}
}
